<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function arr(s) {
      const a = s.split(' ');
      const res = [];
      for (let i = 0; i < a.length; i++) {
        // 取元素该放的位置
        const index = a[i].slice(-1);
        // 取对应位置的值
        const temp = a[i].slice(0, a[i].length - 1)
        res[index - 1] = temp;
      }
      return res.join(' ');
    };
    console.log(arr(s = "is2 sentence4 This1 a3"));
  </script>
</body>

</html>